package com.shinewind.home.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shinewind.home.mapper.IModelMappingMapper;
import com.shinewind.home.service.IModelMappingService;
import com.shinewind.home.service.IModelService;
import com.shinewind.pojo.entity.Model;
import com.shinewind.pojo.entity.ModelMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ModelMappingServiceImpl extends ServiceImpl<IModelMappingMapper, ModelMapping> implements IModelMappingService {
    @Autowired
    private IModelService iModelService;

    @Override
    public Integer getMappingMidByStrMid(String mId) {
        ModelMapping modelMapping = this.lambdaQuery().eq(ModelMapping::getMId,mId).one();
        return modelMapping.getMIdMapping();
    }

    @Override
    public List<Model> getStrMidByMappingMid(List<Integer> recommendModelIds) {
        List<Model> modelList = new ArrayList<>();
        for(int i=0;i< recommendModelIds.size();i++){
            Integer modelId = recommendModelIds.get(i);
            ModelMapping modelMapping = this.lambdaQuery().eq(ModelMapping::getMIdMapping,modelId).one();
            Model model = iModelService.getModelByMId(modelMapping.getMId());
            modelList.add(model);
        }
        return modelList;
    }
}
